Re: [INTERFACES] Questions about pq library and ecpg
| От | Herouth Maoz |
|---|---|
| Тема | Re: [INTERFACES] Questions about pq library and ecpg |
| Дата | |
| Msg-id | l0311070bb32405f4ef56@[147.233.148.142] обсуждение |
| Ответ на | Questions about pq library and ecpg (Antonello De Santis <ua01020@flashnet.it>) |
| Ответы |
Re: [INTERFACES] Questions about pq library and ecpg
|
| Список | pgsql-interfaces |
At 16:43 +0200 on 27/03/1999, Antonello De Santis wrote:
> strcpy(str, 'table');
> result=PQexec(conn, "insert into str values('Rome', 10)");
>
> I guess a code like the above one would not give the expected result..... Is
> there a way to work that out?
> I'm trying to use the ecpg preprocessor to pass arguments of a query in
> variables, but I get a few errors....
IMO, this is too dynamic for ecpg. That is, last time I messed around with
embedded SQL, the format you presented could be used only to substitute
data values, not parts of the query like the name of a table or a field.
It can easily be done with libpq, though. Instead of what you wrote above,
you simply have to build the query correctly:
strcpy( str, 'table_name' );
sprintf( query, "INSERT INTO %s VALUES ('%s', %d)", str, "Rome", 10 );
result = PQexec( conn, query );
...
After the sprintf, the variable query (make sure you allocate enough
memory) will contain "INSERT INTO table_name VALUES ('Rome', 10)".
Herouth
--
Herouth Maoz, Internet developer.
Open University of Israel - Telem project
http://telem.openu.ac.il/~herutma
В списке pgsql-interfaces по дате отправления: